package com.zhangdi.demo.solr.service;

import com.mongodb.client.MongoClient;
import com.zhangdi.demo.solr.entity.User;
import com.zhangdi.demo.solr.repository.UserRepository;
import com.zhangdi.demo.solr.response.Response;
import com.zhangdi.demo.solr.response.ResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoAction;
import org.springframework.data.mongodb.core.MongoAdmin;
import org.springframework.data.mongodb.core.MongoAdminOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 * Created by zhangdi on 2020/06/29 16:02:54.
 */

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserRepository userRepository;

    @Autowired
    MongoTemplate mongoTemplate;

    @Transactional
    @Override
    public Response<User> add(User user) {
        User s = userRepository.insert(user);
        return ResponseUtils.success(s);
    }

    @Override
    public List<User> list() {
        return userRepository.findAll();
    }

    public List<User> findById(List<String> ids) {
        Iterable<User> users = userRepository.findAllById(ids);
        List<User> list = new ArrayList<>();
        for (User user : users) {
            list.add(user);
        }

        return list;
    }
}
